<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/WEB-INF/layout/t.xhtml">

	<ui:define name="title">
		<h:outputText value="Gestione Realizzazioni (passo 2)" />
	</ui:define>
	<ui:define name="roles">
		<f:attribute name="roles" value="scenario" />
	</ui:define>
	<ui:define name="content">
		<h:form>
			<center>
				<p:panel
					header="Gestione Scenario: #{scenarioController.element.name} (passo 2)">
					<h:outputLabel value="Prodotti selezionati" for="display"
						style="font-weight: bolder;" />
					<br />
					<p:outputPanel id="display">
						<ui:repeat value="#{scenarioController.selectedProducts}"
							var="selectedP">
							<h:outputText value="#{selectedP.name}"
								style="font-style: italic;" />
							<br />
						</ui:repeat>
					</p:outputPanel>
					<br />
					<p:commandButton value="Aggiorna prodotti selezionati"
						action="#{scenarioController.updateSelectedProducts}"
						update="display" />
					<br />
					<h:outputText
						value="NB: per mantenere le selezioni già effettuate ed aggiungere o rimuovere una selezione,"
						style="font-weight: bold;" />
					<br />
					<h:outputText
						value="tenere premuto contemporaneamente il tasto ctrl mentre si sceglie una voce."
						style="font-weight: bold;" />
					<br />
					<p:dataTable var="product" value="#{scenarioController.products}"
						rowIndexVar="rowIndex" paginator="true" rows="100"
						rowKey="#{product.id}"
						selection="#{scenarioController.selectedProducts}"
						selectionMode="multiple">

						<p:column width="50">
							<center>
								<h:outputText value="#{rowIndex+1}" />
							</center>
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="nome" />
							</f:facet>
							<h:outputText value="#{product.name}" />
						</p:column>

						<p:column>
							<f:facet name="header">
								<h:outputText value="categoria" />
							</f:facet>
							<h:outputText value="#{product.category.name}" />
						</p:column>

					</p:dataTable>


				</p:panel>
				<br /> <br />

				<h:panelGrid columns="3">
					<h:commandButton action="#{scenarioController.save}"
						rendered="#{empty scenarioController.element.id}" value="Salva" />

					<h:commandButton action="#{scenarioController.update}"
						value="Salva le modifiche" immediate="false"
						rendered="#{not empty scenarioController.element.id}" />

					<h:commandButton id="reset" action="#{scenarioController.reset}"
						value="Annulla" immediate="true" />
				</h:panelGrid>
			</center>

		</h:form>
	</ui:define>
</ui:composition>